import Vue from 'vue'
import MsgComp from './MsgBox.vue'

let tipBox = null;
let MsgBox = Vue.extend(MsgComp);

export default function(msg="默认消息",time=3000){
    let msgVm = new MsgBox({
        data:{
            msg:msg,
            time
        }
    }).$mount()
    console.log(msgVm.$el)
    if(!tipBox){
        tipBox = document.createElement("div");
        // tipBox.classList.add("msg-box");
        tipBox.style.position="fixed";
        tipBox.style.top="0px";
        tipBox.style.left="50%";
        tipBox.style.maxWidth="50%";
        tipBox.style.transform="translate(-50%, 0)";
        tipBox.style.zIndex="999999";
        document.body.appendChild(tipBox);
    }

    tipBox.appendChild(msgVm.$el);

    setTimeout(()=>{
        tipBox.removeChild(msgVm.$el)
        msgVm.$destroy()
    },3000)
}